﻿
namespace Service
{
    using Data.Repository;
    using System.Linq;
	using System.Collections.Generic;

    public class ProductReviewService : IProductReviewService
    {
        private IProductReviewRepository _productReviewRepository;

        #region IProductReviewService Members

        /// <summary>
        /// create new ProductReview
        /// </summary>
        /// <param name="theNewProductReview">the new ProductReview instance</param>
        /// <returns>the new ProductReview's ID</returns>
        public int CreateNewProductReview(Data.Entity.ProductReview theNewProductReview)
        {
            if (theNewProductReview == null)
            {
                return 0;
            }

            if (_productReviewRepository == null)
            {
                _productReviewRepository = new ProductReviewRepository();
            }

            return _productReviewRepository.CreateNewProductReview(theNewProductReview);
        }

        public int DeleteProductReview(int id)
        {
            if (id <= 0)
            {
                return 0;
            }

            if (_productReviewRepository == null)
            {
                _productReviewRepository = new ProductReviewRepository();
            }

            return _productReviewRepository.DeleteProductReview(id);
        }

        public IList<Data.Entity.ProductReview> GetProductReviewsByProduct(int productID)
        {
            if (productID <= 0)
            {
                return null;
            }

            if (_productReviewRepository == null)
            {
                _productReviewRepository = new ProductReviewRepository();
            }

            return _productReviewRepository.GetProductReviewsByProduct(productID);
        }

        public int UpdateProductReview(Data.Entity.ProductReview theProductReview)
        {
            if (theProductReview == null || theProductReview.ProductReviewID <= 0)
            {
                return 0;
            }

            if (_productReviewRepository == null)
            {
                _productReviewRepository = new ProductReviewRepository();
            }

            return _productReviewRepository.UpdateProductReview(theProductReview);
        }

		public IList<Data.Entity.ProductReview> GetAllProductReviewsByLanguage(int languageID)
		{
			if(languageID <= 0)
			{
				return null;
			}

			if(_productReviewRepository == null)
			{
				_productReviewRepository = new ProductReviewRepository();
			}

			return _productReviewRepository.GetAllProductReviewsByLanguage(languageID);
		}

		#endregion
	}
}
